<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>周纪实-添加周纪实</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="static/css/font.css">
    <link rel="stylesheet" href="static/css/xadmin.css">
    <link rel="stylesheet" href="static/lib/layui/css/layui.css">

</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a >首页</a>
        <a >周纪实</a>
        <a>
          <cite>添加周纪实</cite>
        </a>
      </span>
</div>

<!-- f分割线 -->
<div class="layui-card-body">
    <div class="layui-fluid">
        <form class="layui-form" action="" lay-filter="example">
        	<!-- 上面是周计划 -->
        	<hr style="border:none;border-top-width:20px;border-top-style:solid;border-top-color:#008B8B;" />
			<!--
        	<div class="layui-input-block" style="margin-left: 888px; top: 38px">
	            <button type="button" id="newaddbtn" style="margin-top: 5px;width: 110px" class="layui-btn layui-btn-warm">增加周计划</button>
	        </div>
        	-->
            <ul class="addlmrlist-contanerbox">
	            <li id = "lmr-0">
					<!--第几条周计划标识的隐藏域-->
	        		<input type="hidden" value="1" id="weekNum0" name="weekNum">
	                <div class="layui-form-item">
	                    <label  class="layui-form-label layui-required" >周纪实</label>
	                    <div class="layui-input-block" style="width: 666px;">
	                        <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="weekInfo" id="weekInfo0" value="" lay-verify="" autocomplete="off" placeholder="请简要输入周纪实内容以及完成情况"  class="layui-textarea"></textarea>
	                        <!--  <input style="width:1100px!important;" name="weekInfo" id="weekInfo0" value=""  type="text" lay-verify="" autocomplete="off" placeholder="请简要输入周计划内容" class="layui-input">-->
	                    </div>
	                </div>
	                <!--
	                <div class="layui-form-item">
	                    <label  class="layui-form-label layui-required">完成情况</label>
	                    <div class="layui-input-block" style="width: 666px;">
	                        <select name="finshLivel" lay-filter="finshLivel" id="finshLivel0" lay-verify="" autocomplete="off" lay-search>
	                            <option value="">请选择完成情况</option>
	                            <option value="1">完成</option>
	                            <option value="2">基本完成</option>
	                            <option value="3" selected>未完成</option>
	                        </select>
	                    </div>
	                </div>
	                -->
	                <hr style="height:5px;border-color:#0000ff;"/>
	            </li>
            </ul>
            <hr style="border:none;border-top-width:20px;border-top-style:solid;border-top-color:#008B8B;" />
            
			<!-- 下面是临时任务 -->
			<!--
			<div class="layui-input-block" style="margin-left: 888px; top: 38px">
	            <button type="button" id="newaddTempbtn" style="margin-top: 5px;width: 110px" class="layui-btn layui-btn-warm">增加临时任务</button>
	        </div>
	        -->
            <ul class="addlsrwlist-contanerbox">
	            <li id = "lsrw-0">
					<!--第几条周计划标识的隐藏域-->
	        		<input type="hidden" value="0" id="lsrwNum0" name="lsrwNum">
	                <div class="layui-form-item">
	                    <label  class="layui-form-label layui-required" >上级通知以及领导指示及其他重要事项内容</label>
	                    <div class="layui-input-block" style="width: 666px;">
	                        <textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="lsrwInfo" id="lsrwInfo0" value="" lay-verify="" autocomplete="off" placeholder="请简要输入临时任务内容"  class="layui-textarea"></textarea>
	                        <!-- <input style="width:1100px!important;" name="lsrwInfo" id="lsrwInfo0" value=""  type="text" lay-verify="" autocomplete="off" placeholder="请简要输入临时任务内容" class="layui-input"> -->
	                    </div>
	                </div>
	                <!--
	                <div class="layui-form-item">
	                    <label  class="layui-form-label layui-required">完成情况</label>
	                    <div class="layui-input-block" style="width: 666px;">
	                        <select name="finshLivel" lay-filter="lsrwLivel" id="lsrwLivel0" lay-verify="" autocomplete="off" lay-search>
	                            <option value="">请选择完成情况</option>
	                            <option value="1">完成</option>
	                            <option value="2">基本完成</option>
	                            <option value="3" selected>未完成</option>
	                        </select>
	                    </div>
	                </div>
	                -->
	                <hr style="height:5px;border-color:#0000ff;"/>
	            </li>
            </ul>
			
            <div class="layui-input-inline">
        		<button class="layui-btn layui-btn-radius" lay-submit lay-filter="week-add-btn" style="width: 110px">提交</button>
        		<!-- <button class="layui-btn layui-btn-radius" lay-submit lay-filter="week-add-btn">添加</button>  -->
       		</div>
       		
        </form>

    </div>
</div>



</body>
<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="static/lib/layui/layui.js"></script>
<script type="text/javascript" src="static/js/xadmin.js"></script>
<script>
  
	  	
  	
    // 预先加载
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        
        
        
     	// 设置周计划递增初始值
        var lmrIndex = 0;//周计划
        var lmrNameIndex = 1;
     	
        var date = layui.laydate;
     	// 动态添加按钮
        layui.$('#newaddbtn').on('click', function () {
            var form = layui.form;
            // 递增序号
            
            lmrIndex++;
            lmrNameIndex++;
            if(lmrIndex > 2){
            	lmrIndex--;
                lmrNameIndex--;
                layer.alert("最多只能添加3个周计划");
            }else{
            	// id根据lmrIndex依次递增
                //使用下面这个Input
                var weekInfoList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">周小节-' + lmrNameIndex + '</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="weekInfo" id="weekInfo' + lmrIndex + '" value="" lay-verify="" autocomplete="off" placeholder="请简要输入周计划"  class="layui-textarea"></textarea>' +
                    '</div>' +
                    '</div>'
                    
                var finshLivelList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">完成情况</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<select id="finshLivel' + lmrIndex + '" value="" name="finshLivel" lay-verify=""  lay-filter="finshLivel" autocomplete="off" lay-search >' +
                    '   <option value="">请选择完成情况</option>' +
                    '   <option value="1">完成</option>' +
                    '   <option value="2">基本完成</option>' +
                    '   <option value="3" selected>未完成</option>' +
                    '</select>' +
                    '</div>' +
                    '</div><hr style="height:5px;border-color:#0000ff;"/>' 

                var weekNumList =
                    '<input type="hidden" value="'+lmrNameIndex+'" id="weekNum' + lmrIndex + '" name="weekNum">' 
               
                //删除先不加了,不生效
                var delList =
                    '<div className="form-content-sty" style="margin-left: 630px; margin-top: -95px">' +
                    '<button type="button" class="layui-btn layui-btn-danger layui-btn-sm removeclass" id="delbtns" οnclick="dellmr(\'lmr-' + lmrIndex + '\')">删除</button>' +
                    '</div><hr/><hr/>'
                    
                 // 注意 显示出来的顺序在这里设置，跟上面绘制的顺序无关
                var wholeList = '<li id="lmr-' + lmrIndex + '"><div class="lmr-card box-shadow">' + weekNumList + weekInfoList + finshLivelList +'</div></li>'
                $('.addlmrlist-contanerbox').append(wholeList);
                form.render();
            }
        });
     
     	
     	// 设置临时任务递增初始值
        var lsrwIndex = 0;//临时任务
        var lsrwNameIndex = 1;
        layui.$('#newaddTempbtn').on('click', function () {
            var form = layui.form;
            // 递增序号
            
            lsrwIndex++;
            lsrwNameIndex++;
            
            if(lsrwIndex > 2){
            	 lsrwIndex--;
                 lsrwNameIndex--;
                layer.alert("最多只能添加3个临时任务");
            }else{
            	// id根据lsrwIndex依次递增
  
                //使用下面这个Input
                var weekInfoList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">临时任务-' + lsrwNameIndex + '</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<textarea cols="20" rows="3" style="text-align: left;font: 16px 宋体;" type="text" name="lsrwInfo" id="lsrwInfo' + lsrwIndex + '" value="" lay-verify="" autocomplete="off" placeholder="请简要输入临时任务内容"  class="layui-textarea"></textarea>' +
                    '</div>' +
                    '</div>'
                    
                    
                var finshLivelList =
                    '<div class="layui-form-item">' +
                    '<label class="layui-form-label layui-required">完成情况</label>' +
                    '<div class="layui-input-block" style="width: 666px;">' +
                    '<select id="lsrwLivel' + lsrwIndex + '" value="" name="lsrwLivel" lay-verify=""  lay-filter="lsrwLivel" autocomplete="off" lay-search >' +
                    '   <option value="">请选择完成情况</option>' +
                    '   <option value="1">完成</option>' +
                    '   <option value="2">基本完成</option>' +
                    '   <option value="3" selected>未完成</option>' +
                    '</select>' +
                    '</div>' +
                    '</div><hr style="height:5px;border-color:#0000ff;"/>' 

                var weekNumList =
                    '<input type="hidden" value="'+lsrwNameIndex+'" id="lsrwNum' + lsrwIndex + '" name="lsrwNum">' 
               
                //删除先不加了,不生效
                var delList =
                    '<div className="form-content-sty" style="margin-left: 630px; margin-top: -95px">' +
                    '<button type="button" class="layui-btn layui-btn-danger layui-btn-sm removeclass" id="delbtns" οnclick="dellmr(\'lmr-' + lsrwIndex + '\')">删除</button>' +
                    '</div><hr/><hr/>'
                    
                 // 注意 显示出来的顺序在这里设置，跟上面绘制的顺序无关
                var wholeList = '<li id="lmr-' + lsrwIndex + '"><div class="lmr-card box-shadow">' + weekNumList + weekInfoList + finshLivelList +'</div></li>'
                $('.addlsrwlist-contanerbox').append(wholeList);
                form.render();
            }
        });
     
     
     
     	// 监听提交
        form.on('submit(week-add-btn)', function(data){
        	//周计划
        	var addWeekData = [];
            for (var i = 0; i <= lmrIndex; i++) {
            	
            	//var weekNum = document.getElementById("weekNum" + i).value;//第几条周计划：从0开始
            	var weekInfo = document.getElementById("weekInfo" + i).value;//周计划内容
                //var finshLivel = document.getElementById("finshLivel" + i).value;//完成情况：1-完成;2-基本完成;3-未完成
                //var lsrwInfo = document.getElementById("lsrwInfo0").value;//临时任务暂先就一条吧
                
                addWeekData.push({
                	wFlag:"1",
                	weekInfo: weekInfo
                });
                
            }
          	//临时任务
        	var addTempData = [];
            for (var i = 0; i <= lsrwIndex; i++) {
            	//var weekNum = document.getElementById("lsrwNum" + i).value;//第几条周计划：从0开始
            	var lsrwInfo = document.getElementById("lsrwInfo" + i).value;//周计划内容
                //var lsrwLivel = document.getElementById("lsrwLivel" + i).value;//完成情况：1-完成;2-基本完成;3-未完成
                
                addTempData.push({
                	wFlag:"2",
                	tempOraryInfo: lsrwInfo
                    
                });
            }
        	
            //console.log("addWeekData="+JSON.stringify(addWeekData));
            //console.log("addTempData="+JSON.stringify(addTempData));

            $.ajax({
            	type: 'post',
                url: 'empWeekInfo/addWeekInfo.do',
                data: "listWeek="+JSON.stringify(addWeekData)+"&listTemp="+JSON.stringify(addTempData),//将json数据转化为字符串
                dataType: 'json',
                success:function(result){
                	if(result.code==100){
                		 layer.alert("添加周纪实成功", {
                             title: '添加周纪实信息'
                         },
                         function () {
                             window.parent.location.reload();
                             var index = parent.layer.getFrameIndex(window.name);
                             parent.layer.close(index);
                         }
                     );
                	}else{
                		 layer.msg(result.message,{icon: 5,anim: 6});
                	}                            
                }
            });
            return false;
        });
    })
    
    //删除按钮
    function dellmr(id){
    	//alert("id="+id);
        var lmrIndex = id
        lmrIndex --;
        $("#"+id).remove();
    }
    


</script>
</html>
